package p270jp.pxv.android.advertisement.presentation.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.socdm.p087d.adgeneration.ADG;
import com.socdm.p087d.adgeneration.ADGConsts;
import com.socdm.p087d.adgeneration.ADGListener;
import com.socdm.p087d.adgeneration.nativead.ADGInformationIconView;
import com.socdm.p087d.adgeneration.nativead.ADGNativeAd;
import java.util.Objects;
import p062c4.ViewBindings;
import p064c6.Preconditions;
import p072ce.ViewAdgWrapperBinding;
import p072ce.ViewHomeMangaAdItemBinding;
import p189gn.AbstractC3435a;
import p216hn.Lambda;
import p216hn.Reflection;
import p270jp.pxv.android.legacy.model.GoogleNg;
import p284ke.AdUtils;
import p325m0.MutabilityOwnership;
import p350mp.Timber;
import p376no.Koin;
import p404oo.AbstractC5475a;
import p579vo.Qualifier;
import p603wm.AbstractC6949c;
import p677zi.PixivImageLoader;

/* compiled from: MangaGridADGView.kt */
/* renamed from: jp.pxv.android.advertisement.presentation.view.MangaGridADGView */
/* loaded from: classes2.dex */
public final class MangaGridADGView extends FrameLayout implements AbstractC5475a {

    /* renamed from: b */
    public ADG f18794b;

    /* renamed from: a */
    public final AbstractC6949c f18793a = Preconditions.m9801Q(new p312le.MangaGridADGView(this, 0));

    /* renamed from: c */
    public final AbstractC6949c f18795c = Preconditions.m9802P(1, new C4160b(this, null, null));

    /* compiled from: MangaGridADGView.kt */
    /* renamed from: jp.pxv.android.advertisement.presentation.view.MangaGridADGView$a */
    /* loaded from: classes2.dex */
    public static final class C4158a extends ADGListener {

        /* renamed from: a */
        public final Context f18796a;

        /* renamed from: b */
        public final ADG f18797b;

        /* renamed from: c */
        public final AdUtils f18798c;

        /* renamed from: d */
        public final ViewAdgWrapperBinding f18799d;

        /* compiled from: MangaGridADGView.kt */
        /* renamed from: jp.pxv.android.advertisement.presentation.view.MangaGridADGView$a$a */
        /* loaded from: classes2.dex */
        public /* synthetic */ class C4159a {

            /* renamed from: a */
            public static final /* synthetic */ int[] f18800a;

            static {
                int[] iArr = new int[ADGConsts.ADGErrorCode.values().length];
                iArr[ADGConsts.ADGErrorCode.EXCEED_LIMIT.ordinal()] = 1;
                iArr[ADGConsts.ADGErrorCode.NEED_CONNECTION.ordinal()] = 2;
                iArr[ADGConsts.ADGErrorCode.NO_AD.ordinal()] = 3;
                f18800a = iArr;
            }
        }

        public C4158a(Context context, ADG adg, AdUtils aVar, ViewAdgWrapperBinding aVar2) {
            MutabilityOwnership.m3745m(aVar, "adUtils");
            this.f18796a = context;
            this.f18797b = adg;
            this.f18798c = aVar;
            this.f18799d = aVar2;
        }

        @Override // com.socdm.p087d.adgeneration.ADGListener
        public void onFailedToReceiveAd(ADGConsts.ADGErrorCode aDGErrorCode) {
            int i = aDGErrorCode == null ? -1 : C4159a.f18800a[aDGErrorCode.ordinal()];
            if (i != 1 && i != 2 && i != 3) {
                this.f18797b.start();
            }
        }

        @Override // com.socdm.p087d.adgeneration.ADGListener
        public void onReceiveAd() {
            this.f18799d.f5396c.setVisibility(8);
        }

        @Override // com.socdm.p087d.adgeneration.ADGListener
        public void onReceiveAd(Object obj) {
            if (obj instanceof ADGNativeAd) {
                ADGNativeAd aDGNativeAd = (ADGNativeAd) obj;
                if (aDGNativeAd.getIconImage() == null) {
                    Timber.f23100a.mo3525d("ADGNativeAd icon image is null so cannot display", new Object[0]);
                    return;
                }
                this.f18799d.f5396c.setVisibility(8);
                AdUtils aVar = this.f18798c;
                Context context = this.f18796a;
                Objects.requireNonNull(aVar);
                MutabilityOwnership.m3745m(context, "context");
                MutabilityOwnership.m3745m(aDGNativeAd, "nativeAdObject");
                ViewHomeMangaAdItemBinding a = ViewHomeMangaAdItemBinding.m9744a(LayoutInflater.from(context), null, false);
                a.f5406d.addView(new ADGInformationIconView(context, aDGNativeAd, true, ADGInformationIconView.Corner.BOTTOM_LEFT, ADGInformationIconView.BackgroundType.WHITE));
                PixivImageLoader aVar2 = aVar.f20317b;
                String url = aDGNativeAd.getIconImage().getUrl();
                ImageView imageView = a.f5405c;
                MutabilityOwnership.m3746l(imageView, "binding.imageView");
                aVar2.m56j(context, url, imageView);
                a.f5408f.setText(aDGNativeAd.getTitle().getText());
                a.f5407e.setText(aDGNativeAd.getSponsored().getValue());
                aDGNativeAd.setClickEvent(context, a.f5409g, null);
                RelativeLayout relativeLayout = a.f5403a;
                MutabilityOwnership.m3746l(relativeLayout, "binding.root");
                this.f18799d.f5395b.addView(relativeLayout);
                this.f18797b.setAutomaticallyRemoveOnReload(relativeLayout);
            }
        }
    }

    /* compiled from: KoinComponent.kt */
    /* renamed from: jp.pxv.android.advertisement.presentation.view.MangaGridADGView$b */
    /* loaded from: classes2.dex */
    public static final class C4160b extends Lambda implements AbstractC3435a<AdUtils> {

        /* renamed from: a */
        public final /* synthetic */ AbstractC5475a f18801a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4160b(AbstractC5475a aVar, Qualifier aVar2, AbstractC3435a aVar3) {
            super(0);
            this.f18801a = aVar;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, ke.a] */
        @Override // p189gn.AbstractC3435a
        public final AdUtils invoke() {
            return this.f18801a.getKoin().f24118a.m920a().m621a(Reflection.m5499a(AdUtils.class), null, null);
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public MangaGridADGView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        MutabilityOwnership.m3745m(context, "context");
        MutabilityOwnership.m3745m(attributeSet, "attributeSet");
    }

    private final AdUtils getAdUtils() {
        return (AdUtils) this.f18795c.getValue();
    }

    private final ViewAdgWrapperBinding getBinding() {
        return (ViewAdgWrapperBinding) this.f18793a.getValue();
    }

    /* renamed from: a */
    public void m4665a() {
        getBinding().f5396c.setVisibility(0);
        ADG adg = this.f18794b;
        if (adg != null) {
            adg.start();
        }
    }

    @Override // p404oo.AbstractC5475a
    public Koin getKoin() {
        return AbstractC5475a.C5476a.m3211a(this);
    }

    public void setGoogleNg(GoogleNg googleNg) {
        MutabilityOwnership.m3745m(googleNg, "googleNg");
    }

    public final void setup(String str) {
        MutabilityOwnership.m3745m(str, "locationId");
        ADG adg = this.f18794b;
        if (adg != null) {
            getBinding().f5395b.removeView(adg);
            ViewBindings.m9831f(adg);
        }
        ADG adg2 = new ADG(getContext());
        adg2.setLocationId(str);
        adg2.setUsePartsResponse(true);
        adg2.setReloadWithVisibilityChanged(false);
        adg2.setInformationIconViewDefault(false);
        Context context = adg2.getContext();
        MutabilityOwnership.m3746l(context, "context");
        AdUtils adUtils = getAdUtils();
        ViewAdgWrapperBinding binding = getBinding();
        MutabilityOwnership.m3746l(binding, "binding");
        adg2.setAdListener(new C4158a(context, adg2, adUtils, binding));
        this.f18794b = adg2;
        addView(adg2);
    }
}
